package com.yuezhu.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.yuezhu.R;
import com.yuezhu.control.TaskEngine;
import com.yuezhu.global.ParallaxSwipeBackActivity;
import com.yuezhu.util.LogUtils;
import com.yuezhu.util.MyToast;
import com.yuezhu.util.StringUtil;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by Administrator on 2016/6/12.
 */
public class SendMailActivity extends ParallaxSwipeBackActivity {
    @InjectView(R.id.bottom_left)
    View bottom_left;
    @InjectView(R.id.bottom_middle)
    View bottom_middle;
    @InjectView(R.id.bottom_right)
    View bottom_right;
    @InjectView(R.id.tv_send_email)
    TextView send;
    @InjectView(R.id.iv_bottome_left)
    ImageView ivBottomeLeft;
    @InjectView(R.id.iv_bottome_middle)
    ImageView ivBottomeMiddle;
    @InjectView(R.id.iv_bottome_right)
    ImageView ivBottomeRight;
    @InjectView(R.id.iv_menu)
    ImageView ivMenu;
    @InjectView(R.id.tv_title)
    TextView tvTitle;
    @InjectView(R.id.iv_quite)
    ImageView ivQuite;
    private String authToken;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_send_mail);
        ButterKnife.inject(this);
        authToken = getIntent().getStringExtra("authToken");
        send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                TaskEngine.getInstance().startSendMailTask(queue, authToken, ResponseLis, Errorlis);
            }
        });
        ivBottomeMiddle.setImageResource(R.drawable.message_left);
        ivBottomeMiddle.setVisibility(View.VISIBLE);
        bottom_middle.setVisibility(View.VISIBLE);
        ivBottomeLeft.setVisibility(View.GONE);
        bottom_left.setVisibility(View.GONE);
        ivBottomeRight.setVisibility(View.GONE);
        bottom_right.setVisibility(View.GONE);
        ivBottomeMiddle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        ivMenu.setImageResource(R.drawable.back_icon);
        ivMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        ivQuite.setVisibility(View.INVISIBLE);
        tvTitle.setText("激活邮件");
    }

    // 注册成功
    Response.Listener ResponseLis = new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject json) {
            LogUtils.e("登录成功" + "sec" + json.toString());
            try {
                String respDesc = json.getString("respDesc");
                String respCode = json.getString("respCode");
                int respNo = json.getInt("respNo");
                if (!StringUtil.equal(respCode, "OK")) {
                    MyToast.showDefaltToast(respDesc);
                } else {
                    MyToast.showDefaltToast(respDesc);
                }
                finish();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

    };

    /**
     * 注册失败
     */
    Response.ErrorListener Errorlis = new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {
            LogUtils.e("登录失败", "error  " + volleyError.toString());
        }
    };
}
